<!DOCTYPE html>
<html>
<head>
<title>req_assign</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />

<link rel="stylesheet" type="text/css"
	href="/codebase/fonts/font_roboto/roboto.css" />
<link rel="stylesheet" type="text/css" href="/codebase/dhtmlx.css" />
<script type="text/javascript" src="/codebase/dhtmlxform.js" />
<script type="text/javascript" src="/codebase/dhtmlxgrid.js" />
<!-- <script type="text/javascript" src="/codebase/dhtmlx.js" /> -->
<style>
</style>
<script>
/*<![CDATA[*/
	var myForm, myGrid, my_list_label;
	function doOnLoad() {
		
		var v=document.getElementById("assign_test_id").innerHTML;
		
		if (myForm) {
			myForm.unload();
			myForm = null;
		}
		myForm = new dhtmlXForm("form_req_base_info");
		//myForm.loadStruct("/common/testmanager/test_modify_detail_test_info.xml");
		myForm.loadStruct("/test/test_modify_detail_team_info_onload?test_id="+v);
		
		myForm.attachEvent("onButtonClick",function(name){
			/* if (name == "add1" || name == "remove1") {
				change_req_head(name=="add1");
			}; */
			/* if (name == "add2" || name == "remove2") {
				change_req_analyst(name=="add2");
			};	 */
			if (name == "add3" || name == "remove3") {
				change_test_executor(name=="add3");
			};	
			if (name == "team_info_save_btn") {		
				/* var s2=myForm.getSelect("req_analyst");
				for (var i=0;i<s2.options.length;i++)
				{
					s2.options[i].selected=true
				}		 */		
				var s3=myForm.getSelect("test_executor");
				for (var i=0;i<s3.options.length;i++)
				{
					s3.options[i].selected=true
				}	
				myForm.send("/test/test_modify_detail_team_info_save",callback);
				
			}
			
		});
		
		//grid setup
		if (myGrid) {
			myGrid.clearAll(true);
		}
		myGrid = new dhtmlXGridObject("grid_team_list");
		//myGrid.loadStruct("/common/testmanager/req_list.xml");
		myGrid.setImagePath("/codebase/imgs/");

		myGrid.setHeader("日期,姓名,调入/调出,备注");
		myGrid.setInitWidths("150,100,100,250");
		myGrid.setColAlign("center,left,left,left");
		myGrid.setColTypes("ro,ro,ro,ro");
		myGrid.setColSorting("str,str,str,str");
		//myGrid.setColumnIds("first,second");
		myGrid.xml.top = "mytop";
		myGrid.xml.row = "./myrow";
		//myGrid.enableAutoWidth(true);
		//myGrid.enableAutoHeight(true);
		myGrid.init();
		//myGrid.load("/common/testmanager/req_modify_detail_team_info_test_data.xml","xml");
		myGrid.load("/test/test_modify_detail_team_info_grid?test_id=" + v,"json");
	}
	function change_req_head(block) {
		
		var ida = (block?"req_head":"req_head_all");
		var idb = (block?"req_head_all":"req_head");
		
		var sa = myForm.getSelect(ida);
		var sb = myForm.getSelect(idb);
		
		var t = myForm.getItemValue(ida);
		if (t.length == 0) return;
		eval("var k={"+t.join(":true,")+":true};");
		
		var w = 0;
		var ind = -1;
		while (w < sa.options.length) {
			if (k[sa.options[w].value]) {
				sb.options.add(new Option(sa.options[w].text,sa.options[w].value));
				sa.options.remove(w);
				ind = w;
			} else {
				w++;
			}
		}
		
		if (sa.options.length > 0 && ind >= 0) {
			if (sa.options.length > 0) sa.options[t.length>1?0:Math.min(ind,sa.options.length-1)].selected = true;
		}
		
	}

/* 	function change_req_analyst(block) {
		
		var ida = (block?"req_analyst":"req_analyst_all");
		var idb = (block?"req_analyst_all":"req_analyst");
		
		var sa = myForm.getSelect(ida);
		var sb = myForm.getSelect(idb);
		
		var t = myForm.getItemValue(ida);
		if (t.length == 0) return;
		eval("var k={"+t.join(":true,")+":true};");
		
		var w = 0;
		var ind = -1;
		while (w < sa.options.length) {
			if (k[sa.options[w].value]) {
				sb.options.add(new Option(sa.options[w].text,sa.options[w].value));
				sa.options.remove(w);
				ind = w;
			} else {
				w++;
			}
		}
		
		if (sa.options.length > 0 && ind >= 0) {
			if (sa.options.length > 0) sa.options[t.length>1?0:Math.min(ind,sa.options.length-1)].selected = true;
		}
		
	} */

	function change_test_executor(block) {
		
		var ida = (block?"test_executor":"test_executor_all");
		var idb = (block?"test_executor_all":"test_executor");
		
		var sa = myForm.getSelect(ida);
		var sb = myForm.getSelect(idb);
		
		var t = myForm.getItemValue(ida);
		if (t.length == 0) return;
		eval("var k={"+t.join(":true,")+":true};");
		
		var w = 0;
		var ind = -1;
		while (w < sa.options.length) {
			if (k[sa.options[w].value]) {
				sb.options.add(new Option(sa.options[w].text,sa.options[w].value));
				sa.options.remove(w);
				ind = w;
			} else {
				w++;
			}
		}
		
		if (sa.options.length > 0 && ind >= 0) {
			if (sa.options.length > 0) sa.options[t.length>1?0:Math.min(ind,sa.options.length-1)].selected = true;
		}
		
	}

	var callback=function () {
		//alert("callback");
		
		if(arguments[1]=="true"){
			alert("保存修改成功");	
			var v=document.getElementById("assign_test_id").innerHTML;
			myGrid.clearAndLoad("/test/test_modify_detail_team_info_grid?test_id=" + v,"json");
		}
		else{
			alert("保存修改成功，错误信息："+arguments[1]);
		}
	}
/*]]>*/	
</script>
</head>
<body onload="doOnLoad();">
<div id="assign_test_id" name="assign_test_id" th:text="${test_id}" style="display: none;" > </div>
		<table>
			<tr>
			<td>
				<div id="myForm" style="width: 800px;"></div>
				</td>
		</tr>
		<tr>
			<td>
				<div id="form_req_base_info"></div>
			</td>
		</tr>

	</table>
	<table>
		<tr>
			<td>
				<div id="grid_team_list"
					style="width: 700px; height: 200px; background-color: white;">
				</div>
			</td>
		</tr>
	</table>
</body>
</html>